import 'package:exams_app/widget/hexcolor.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'logic.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';



class MessageModulePage extends StatelessWidget {

  final MessageModuleLogic logic = Get.put(MessageModuleLogic());

  @override
  int page = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('消息'),
        centerTitle: true,
      ),
      body: GetBuilder<MessageModuleLogic>(
        initState: (sz){
          logic.requestDataWithCollection(true,page: 0);
        },
        builder: (logic) {
          return EasyRefresh.custom(
            controller: logic.esController,
            emptyWidget: logic.emptyData(),
            header: MaterialHeader(),
            footer: MaterialFooter(),
            onRefresh: logic.onRefresh,
            onLoad: logic.onLoad,
            slivers: [
              SliverList(delegate: SliverChildBuilderDelegate(
                  _buildListItem, childCount: logic.dataList.length))
            ],
          );
        },
      ),
    );
  }

  Widget _buildListItem(BuildContext context, int index) {

    Data model = logic.dataList[index];
    return Column(
      children: [
        Container(
          padding: EdgeInsets.only(top: 15),
          child: Text('${model.sendingTime}',style: TextStyle(fontSize: 12,color:Colors.grey[280]),),
        ),
        Container(
          width: Get.width,
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.circular(10.0),
          ),
          margin: EdgeInsets.all(15),
          // height: 80,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [

              Container(
                padding: EdgeInsets.only(top: 10,left: 15),
                child:Text('${model.name}',style: TextStyle(fontSize: 16,color: HexColor('#333333'),fontWeight: FontWeight.w500),),
              ),

              Container(
                padding: EdgeInsets.only(top: 15,left: 15,bottom: 15),
                child:  Text('${model.message}',
                  style: TextStyle(fontSize: 14,color: HexColor('#999999')),maxLines: 100,),
              )

            ],
          ),
        )
      ],
    );
  }

}
